<script setup lang="ts" name="MagicCubeProperty">
import { usePropertyForm } from '@/components/Designer/utils/index'
import { MagicCubeProperty } from './config'

/** 广告魔方属性面板 */

const props = defineProps<{ modelValue: MagicCubeProperty }>()
const emit = defineEmits(['update:modelValue'])
const { formData } = usePropertyForm(props.modelValue, emit)

// 选中的热区
const selectedHotAreaIndex = ref(-1)
const handleHotAreaSelected = (_: any, index: number) => {
  selectedHotAreaIndex.value = index
}
</script>

<template>
  <MallProperty v-model="formData.style">
    <!-- 表单 -->
    <ElForm label-width="80px" :model="formData" class="m-t-8px">
      <ElText tag="p"> 魔方设置 </ElText>
      <ElText type="info" size="small"> 每格尺寸187 * 187 </ElText>
      <MagicCube v-model="formData.list" class="m-y-16px" :rows="4" :cols="4" @hot-area-selected="handleHotAreaSelected" />
      <template v-for="(hotArea, index) in formData.list" :key="index">
        <template v-if="selectedHotAreaIndex === index">
          <ElFormItem label="上传图片" :prop="`list[${index}].imgUrl`">
            <UploadImage v-model="hotArea.imgUrl" height="80px" width="80px" />
          </ElFormItem>
          <ElFormItem label="链接" :prop="`list[${index}].url`">
            <MallAppLinkInput v-model="hotArea.url" />
          </ElFormItem>
        </template>
      </template>
      <ElFormItem label="上圆角" prop="borderRadiusTop">
        <ElSlider v-model="formData.borderRadiusTop" :max="100" :min="0" show-input input-size="small" :show-input-controls="false" />
      </ElFormItem>
      <ElFormItem label="下圆角" prop="borderRadiusBottom">
        <ElSlider v-model="formData.borderRadiusBottom" :max="100" :min="0" show-input input-size="small" :show-input-controls="false" />
      </ElFormItem>
      <ElFormItem label="间隔" prop="space">
        <ElSlider v-model="formData.space" :max="100" :min="0" show-input input-size="small" :show-input-controls="false" />
      </ElFormItem>
    </ElForm>
  </MallProperty>
</template>

<style scoped lang="scss"></style>
